<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>

<script type="text/javascript">
    var rowId = 0;
    
    $('.ui-reset , #refresh_loanappGrid').click(function(){
        $("#loanappGrid").jqGrid('setGridParam',{search:false});
        var postData = $("#loanappGrid").jqGrid('getGridParam','postData');
        $.extend(postData,{searchField:"",searchString:"",searchOper:""});
        $.extend(postData,{filters:""});
        $("#loanappGrid").trigger("reloadGrid");
    });
    
    $.subscribe('loanappGridRowSelected', function(event,data) {
        rowId = event.originalEvent.id;
        $( "#loanappGrid_edit" ).button( "option", "disabled", false );
    });

    $.subscribe('searchLoanappGrid', function(event,data) {
        $("#loanappGrid").jqGrid('searchGrid', {drag:true,closeAfterSearch:true,closeOnEscape:true,sopt:['eq'],caption:"Search Employee"} );
    });
    
    $.subscribe('loanappGridComplete',function(event,data){
        $( "#loanappGrid_search" ).button( "option", "disabled", false );
        $( "#loanappGrid_showhide" ).button( "option", "disabled", false );
    });
    
    $.subscribe('showhideLoanappGrid', function(event,data) {
        $("#loanappGrid").jqGrid('setColumns',{});
    });
    
    $.subscribe('editLoanappGrid', function(event,data) {
        if(rowId!=0){
            $("#loanappGrid").jqGrid('editGridRow',rowId,{drag:true,closeAfterEdit:true,closeOnEscape:true,jqModal:true,width:350,left:310,top:20,reloadAfterSubmit:true,afterSubmit:function(response, postdata) {return isError(response.responseText);}});
        }else{
            alert("Sorry. Please select a loan application first.");
        }
    });
    
    function isError(text) {
        if(text.indexOf('ERROR') >= 0) { return [false, text]; }
        return [true,''];
    }
</script>
<div class="gridOptsContainer">
    <sj:submit button="true" cssStyle="font-size:14px;" disabled="true" id="loanappGrid_search" onClickTopics="searchLoanappGrid" value="Search Loan Applications"/>
    <sj:submit button="true" cssStyle="font-size:14px;" disabled="true" id="loanappGrid_showhide" onClickTopics="showhideLoanappGrid" value="Show/Hide Columns"/>
    <s:if test="#session.branch.branchname!='Head Office'">
        <sj:submit button="true" cssStyle="font-size:14px;" disabled="true" id="loanappGrid_edit" onClickTopics="editLoanappGrid" value="Edit Loan Application"/>
    </s:if>
</div>
<s:url id="remoteurl" action="grid-loanapp"/>
<s:url id="editurl" action="edit-loanapp"/>
<s:url id="selectOptionsStat" action="select-loanappstat"/>
<sjg:grid
    id="loanappGrid"
    caption="Cashmate Loan Applications"
    dataType="json"
    href="%{remoteurl}"
    editurl="%{editurl}"
    gridModel="gridModel"
    pager="true"
    pagerButtons="true"
    pagerInput="true"
    rowList="15,30,50"
    rowNum="15"
    loadingText="Requesting Data..."
    width="970"
    shrinkToFit="false"
    hoverrows="true"
    rownumbers="true"
    autoencode="true"
    viewrecords="true"
    navigator="true"
    navigatorAdd="false"
    navigatorDelete="false"
    navigatorEdit="false"
    navigatorSearch="true"
    navigatorView="true"
    onSelectRowTopics="loanappGridRowSelected"
    onGridCompleteTopics="loanappGridComplete"
    >
    
<!--    groupField="['area']"-->
    
    <sjg:gridColumn name="loanappid"
                    key="true"
                    index="loanappid"
                    title="loanappid"
                    sortable="false"
                    hidden="true"
                    align="center"
                    />
    
    <sjg:gridColumn name="documentno"
                    index="documentno"
                    title="Document No."
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="borrowerCode"
                    index="borrowerCode"
                    title="Borrower Code"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />
    
    <sjg:gridColumn name="borrowername"
                    index="borrowername"
                    title="Borrower Name"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />
    
    <sjg:gridColumn name="area"
                    index="area"
                    title="Area"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />
    
    <sjg:gridColumn name="applicationdate"
                    index="applicationdate"
                    title="Application Date"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="idnumber"
                    index="idnumber"
                    title="Employee ID"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="presentstreetaddress"
                    index="presentstreetaddress"
                    title="Present Steet Address"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="presentbarangay"
                    index="presentbarangay"
                    title="Present Barangay"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="presentcityormunicipality"
                    index="presentcityormunicipality"
                    title="Present City"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="presentprovince"
                    index="presentprovince"
                    title="Present Province"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="presentpostalcode"
                    index="presentpostalcode"
                    title="Present Postal Code"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'4'}"
                    editrules="{required:true,number:true}"
                    align="center"
                    />

    <sjg:gridColumn name="provincialstreetaddress"
                    index="provincialstreetaddress"
                    title="Provincial Street Address"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="provincialbarangay"
                    index="provincialbarangay"
                    title="Provincial Baranagay"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="provincialcityormunicipality"
                    index="provincialcityormunicipality"
                    title="Provincial City"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="provincialprovince"
                    index="provincialprovince"
                    title="Provincial Province"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="provincialpostalcode"
                    index="provincialpostalcode"
                    title="Provincial Postal Code"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="presentaddressstatus"
                    index="presentaddressstatus"
                    title="Present Adrress Status"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="presentaddresslengthofstayinyears"
                    index="presentaddresslengthofstayinyears"
                    title="Present Length of Stay (years)"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'3'}"
                    editrules="{required:true,number:true}"
                    align="center"
                    />

    <sjg:gridColumn name="presentaddresslengthofstayinmonths"
                    index="presentaddresslengthofstayinmonths"
                    title="Present Length of Stay (months)"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'5'}"
                    editrules="{required:true,number:true}"
                    align="center"
                    />

    <sjg:gridColumn name="provincialaddressstatus"
                    index="provincialaddressstatus"
                    title="Provincial Adrress Status"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="provincialaddresslengthofstayinyears"
                    index="provincialaddresslengthofstayinyears"
                    title="Provincial Length of Stay (years)"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'3'}"
                    editrules="{required:true,number:true}"
                    align="center"
                    />

    <sjg:gridColumn name="provincialaddresslengthofstayinmonths"
                    index="provincialaddresslengthofstayinmonths"
                    title="Provincial Length of Stay (months)"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'5'}"
                    editrules="{required:true,number:true}"
                    align="center"
                    />

    <sjg:gridColumn name="spousefirstname"
                    index="spousefirstname"
                    title="Spouse First Name"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="spousemiddlename"
                    index="spousemiddlename"
                    title="Spouse Middle Initial"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'3'}"
                    align="center"
                    />

    <sjg:gridColumn name="spouselastname"
                    index="spouselastname"
                    title="Spouse Last Name"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="spousedateofbirth"
                    index="spousedateofbirth"
                    title="Spouse Birthdate"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    hidden="true"
                    align="center"
                    />

    <sjg:gridColumn name="spouseplaceofbirth"
                    index="spouseplaceofbirth"
                    title="Spouse Place of Birth"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="spousereligion"
                    index="spousereligion"
                    title="Spouse Religion"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="spousecitizenship"
                    index="spousecitizenship"
                    title="Spouse Citizenship"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="spouseprovincialstreetaddress"
                    index="spouseprovincialstreetaddress"
                    title="Spouse Provincial Address"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="spouseprovincialbarangay"
                    index="spouseprovincialbarangay"
                    title="Spouse Provincial Barangay"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="spouseprovincialcityormunicipality"
                    index="spouseprovincialcityormunicipality"
                    title="Spouse Provincial City"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="spouseprovincialprovince"
                    index="spouseprovincialprovince"
                    title="Spouse Provincial Province"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="spouseprovincialpostalcode"
                    index="spouseprovincialpostalcode"
                    title="Spouse Provincial Postal Code"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="coborrowerfirstname"
                    index="coborrowerfirstname"
                    title="Co-Borrower First Name"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="coborrowermiddlename"
                    index="coborrowermiddlename"
                    title="Co-Borrower Middle Initial"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'3'}"
                    align="center"
                    />

    <sjg:gridColumn name="coborrowerlastname"
                    index="coborrowerlastname"
                    title="Co-Borrower Last Name"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="coborrowerstreetaddress"
                    index="coborrowerstreetaddress"
                    title="Co-Borrower Street Address"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="coborrowerbarangay"
                    index="coborrowerbarangay"
                    title="Co-Borrower Barangay"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="coborrowercityormunicipality"
                    index="coborrowercityormunicipality"
                    title="Co-Borrower City"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="coborrowerprovince"
                    index="coborrowerprovince"
                    title="Co-Borrower Province"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="coborrowerpostalcode"
                    index="coborrowerpostalcode"
                    title="Co-Borrower Postal Code"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="coborrowerreligion"
                    index="coborrowerreligion"
                    title="Co-Borrower Religion"
                    sortable="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    align="center"
                    />

    <sjg:gridColumn name="status"
                    index="status"
                    title="Application Status"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    editable="true"
                    edittype="text"
                    editoptions="{dataUrl : '%{selectOptionsStat}'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="amountrequested"
                    index="amountrequested"
                    title="Amount Requested"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="suggestedamount"
                    index="suggestedamount"
                    title="Suggested Amount"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="amortizationindays"
                    index="amortizationindays"
                    title="Ammortization (days)"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="remarks"
                    index="remarks"
                    title="Remarks"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="releasedate"
                    index="releasedate"
                    title="Release Date"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    align="center"
                    />

    <sjg:gridColumn name="requestseriesno"
                    index="requestseriesno"
                    title="Request Series No."
                    sortable="true"
                    hidden="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />
    
     <sjg:gridColumn name="requestDocumentNo"
                    index="requestDocumentNo"
                    title="Loan Request Document"
                    sortable="true"
                    search="true"
                    align="center"
                    />
    
    
</sjg:grid>
